package com.zzw.thread;

public class DrawThread extends Thread {

	private Account account;
	private double drawAmount;
	public DrawThread(String name,Account account,double drawAmount){
		super(name);
		this.account = account;
		this.drawAmount = drawAmount;
	}
	
	public void run(){
		synchronized(account){
			if(account.getBalance() >= drawAmount){
				System.out.println("" + drawAmount);
			
				account.setBalance(account.getBalance() - drawAmount);;
				System.out.println("" + account.getBalance());
			}
			else{
				System.out.println(getName() + "");
			}
		}
	}
	
	public static void main(String[] args) {
		Account account = new Account("123456", 1000);
		new DrawThread("", account, 500).start();
		new DrawThread("", account, 800).start();
	}
	
}